import request from "@/utils/request";

export default {
  batchInsert(data) {
    data = "" ? [] : data;
    let chatperId = data.chapter;
    if (chatperId == "") {
      chatperId = [];
    }
    data.chapter = chatperId;
    return request({
      url: `/questionItem/batchInsert`,
      method: "post",
      data,
    });
  },

  batchGet(data) {
    return request({
      url: `/questionItem/batchGet/${data}`,
      method: "get",
    });
  },
  getItem(questionItemId) {
    return request({
      url: `/questionItem/getItem/${questionItemId}`,
      method: "get",
    });
  },
  submit(score, seconds, questionItemId, name, allAnswers, ids, title) {
    const data = {
      score,
      seconds,
      questionItemId,
      name,
      allAnswers,
      ids,
      title,
    };
    return request({
      url: `/questionItem/submit`,
      method: "post",
      data,
    });
  },
  getAllItem() {
    return request({
      url: `/questionItem/getAllItem`,
      method: "get",
    });
  },
  checkForStudent(data) {
    return request({
      url: `/questionItem/checkForStudent/${data}`,
      method: "get",
    });
  },
  /**
   * 获取某人考过的考卷填写的答案
   */
  getMyAnswers(questionItemId, account) {
    return request({
      url: `/questionItem/getMyAnswers/${questionItemId}/${account}`,
      method: "get",
    });
  },

  /**
   * 获取所有考卷
   */
  getResultList(title, time, currentPage, pageSize) {
    let startTime = null;
    let endTime = null;
    if (time) {
      startTime = time[0];
      endTime = time[1];
    }
    const data = {
      params: { title, startTime, endTime },
      currentPage,
      pageSize,
    };
    return request({
      url: `/questionItem/getResultList`,
      method: "post",
      data,
    });
  },

  getResultTotal(title, time) {
    let startTime = null;
    let endTime = null;
    if (time) {
      startTime = time[0];
      endTime = time[1];
    }
    const data = { title, startTime, endTime };
    return request({
      url: `/questionItem/getResultTotal`,
      method: "post",
      data,
    });
  },
  /**
   * 删除考卷
   * @param {考卷的id} questionItemId
   * @returns
   */
  delete(questionItemId) {
    return request({
      url: `/questionItem/delete/${questionItemId}`,
      method: "delete",
    });
  },
  /**
   * 批量删除考卷
   */
  batchDelete(data) {
    return request({
      url: `/questionItem/batchDelete`,
      method: "post",
      data,
    });
  },
  /**
   * 获取随堂练习的类型和课程
   * @param {练习的类型} type
   * @param {练习的课程} selectedId
   */
  getLearnItems(type, selectedId) {
    return request({
      url: `/questionItem/getLearnItems/${type}/${selectedId}`,
      method: "get",
    });
  },
  /**
   * 根据问题题目模糊查询
   * @param {问题的题目} question
   */
  getLearnItemsByQuestion(question) {
    return request({
      url: `/questionItem/getLearnItemsByQuestion/${question}`,
      method: "get",
    });
  },

  /**
   * 查询改名学员有哪些需要考的试卷
   */
  selectQuestionItems(name, currentPage, pageSize) {
    name = name ? name : "_";
    return request({
      url: `/questionItem/selectQuestionItems/${name}/${currentPage}/${pageSize}`,
      method: "get",
    });
  },
  /**
   * 
    查询该科目和该班级一共出了多少份试卷
  */
  getCount(subjectId, gradeId) {
    return request({
      url: `/questionItem/getCount/${subjectId}/${gradeId}`,
      method: "get",
    });
  },

  /**
   * 查询该学员还有多少道试卷未做
   */
  getCountByAccount() {
    return request({
      url: `/questionItem/getCountByAccount`,
      method: "get",
    });
  },
};
